package com.itheima.dao.store;

import com.itheima.domain.store.QuestionItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface QuestionItemDao {

    /**
     * 根据题目ID查询对应的选项列表
     * @param questionId
     * @return
     * @throws Exception
     */
    @Results(id = "questionItemResults",value = {
            @Result(property = "id",column = "id"),
            @Result(property = "questionId",column = "question_id"),
            @Result(property = "content",column = "content"),
            @Result(property = "isRight",column = "is_right"),
    })
    @Select("select * from st_question_item where question_id=#{x}")
    List<QuestionItem> findByQuestionId(String questionId)throws Exception;


    @Insert("INSERT INTO `st_question_item` ( `id`, `question_id`, `content`, `is_right` ) VALUES ( #{id},#{questionId},#{content},#{isRight}) ; ")
    int save(QuestionItem questionItem);

    /**
     * 根据选项的ID查询选项详情
     * @param id
     * @return
     * @throws Exception
     */
    @Select("select * from st_question_item where id=#{x}")
    @ResultMap("questionItemResults")
    QuestionItem findById(String id)throws Exception;

    @Update("update st_question_item set content=#{content}, is_right=#{isRight} where id=#{id}")
    int update(QuestionItem questionItem)throws Exception;


    @Delete("delete from st_question_item where id=#{x}")
    int delete(String id)throws Exception;
}
